// Name: SwitchDict_x50
// Description: Contains options related to tap actions, swipe actions & zoom
//
// Author: Terisa
//
// History:
//	2012-02-28 Terisa - Initial version
//	2012-04-13 Analogus: minor changes; new path for DIC; 
//	2012-04-15 Analogus: added option for dictionary-path;
//	2012-04-27 Analogus: added options for DIC1.pdf and DIC1.epub
//	2012-06-10 Mark Nord - UTF-8 encoding, var-defs, now working in BETA-folder

tmp = function() {

	var 
		L = Core.lang.getLocalizer('SwitchDict'),
		log = Core.log.getLogger('SwitchDict'),
		/*** GENERAL ***/
		model = kbook.model,
		actionName2action = {},

	SwitchDictFunction = function () 
	{
		var mpath, path, cb ;
		try {
			
			switch (SwitchDict.options.Option_Dic_Path)
				{
				case 'EPUB':
					var path = "/Data/Books/DIC.epub" ;
					var mPath = "Books/DIC.epub" ;
				break;

				case 'EPUB1':
					var path = "/Data/Books/DIC1.epub" ;
					var mPath = "Books/DIC1.epub" ;
				break;	

				case 'EPUB2':
					var path = "/Data/Books/DIC2.epub" ;
					var mPath = "Books/DIC2.epub" ;
				break;						
				
				case 'PDF1':
					var path = "/Data/Books/DIC1.pdf" ;
					var mPath = "Books/DIC1.pdf" ;
				break;
				
				case 'PDF2':
					var path = "/Data/Books/DIC2.pdf" ;
					var mPath = "Books/DIC2.pdf" ;
				break;
				
				default:
					var path = "/Data/Books/DIC.pdf" ;	
					var mPath = "Books/DIC.pdf" ;				
				};
				
			log.error ('path: ', path) ;

			//cb = this.currentBook ;
			cb = Core.ui.getCurrentNode();
			log.error ('Antes libro') ;
			if (cb)
			{
				currentPath = cb.media.path ;
				log.error ('Libro: ', currentPath) ;
				bookHistoryNode = Core.addonByName.BookHistory.getAddonNode () ;
				log.error ('get history') ;
				
				if (mPath != currentPath) // No estamos en el diccionario
					{
						log.error ('Switch to dictionary') ;
						node = Core.media.createMediaNode (path, bookHistoryNode) ;
						log.error ('Attempting to create node') ;
						
						if (node != null) 
							{
								log.error ('create node') ;
								Core.ui.showMsg(L("OPENING_DIC"), 0);
								bookHistoryNode.gotoNode(node, model);
							} 
						else 
							{
								log.error ('Node Error') ;
								Core.ui.showMsg(L("ERROR_OPENING_DIC"), 0);
							}
					}
				else // Estamos en el diccionario
					{
						log.error ('Estamos en el diccionario') ;
						bookHistoryList = Core.addonByName.BookHistory.getBookList () ;
						log.error ('History obtained') ;
						Core.addonByName.BookHistory.actions[1].action () ;
					}
			}
		}catch (e){
			log.error('SwitchDict', e);
		}	
	},
	
	
	SwitchDict = {
			name: 'SwitchDict',
	        	title: L('TITLE'),
			settingsGroup: "additional", 
			icon: 'STYLUS', 
			//Options:
			optionDefs: 
			[
				{
				name: 'Option_Dic_Path',	
				title: L('OPTION_DIC_PATH'),
				icon: 'DICTIONARY',
				helpText: L('HELP_DIC_PATH'),
				defaultValue: 'PDF',
				values: ['PDF', 'EPUB', 'PDF1', 'EPUB1', 'PDF2', 'EPUB2'],
				valueTitles: 
					{
					'PDF': L('/Books/DIC.pdf'), 
					'EPUB': L('/Books/DIC.epub'),
					'PDF1': L('/Books/DIC1.pdf'), 
					'EPUB1': L('/Books/DIC1.epub'),
					'PDF2': L('/Books/DIC2.pdf'), 
					'EPUB2': L('/Books/DIC2.epub') 
					}
				},
			],
		
			//Actions:
			actions: 
			[
				{
				name: 'SwitchDict',
				title: L('SWITCH_DICT'),
				group: 'Book',
				icon: 'DICTIONARY',
				action: function () {
					log.error ('En accion') ;
					SwitchDictFunction () ;
				}
				}
			], 
		
		//On Settings:
/*		
	onSettingsChanged: function (propertyName, oldValue, newValue, object) 
		{
			switch (propertyName) 
			{
				case 'Option_Dic_Path':
							;
					break ;		
			}
		}
*/
	};

	Core.addAddon(SwitchDict);
};
try {
	tmp();
} catch (e) {
	// Core's log
	log.error('in SwitchDict.js', e);
}

